package com.example.controller;

import com.example.anno.Log;
import com.example.pojo.Result;
import com.example.pojo.Dept;
import com.example.service.impl.DeptServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptServiceImpl deptService;

    @GetMapping
    public Result list() {
        List<Dept> deptList = deptService.list();
        return Result.succeed(deptList);
    }

    @DeleteMapping("/{id}")
    @Log
    public Result deleteById(@PathVariable Integer id) {
        deptService.deleteById(id);
        return Result.succeed();
    }
    @PostMapping
    @Log
    public Result add(@RequestBody Dept dept){
        deptService.add(dept);
        return Result.succeed();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Dept dept=deptService.getById(id);
        return Result.succeed(dept);
    }
    @PutMapping
    @Log
    public Result update(@RequestBody Dept dept){
        deptService.update(dept);
        return Result.succeed();
    }
}
